
package async

import (
	"syscall"
	"unsafe"
	"syscall/fibril"
)


// Must be kept synchronized with <ipc/common.h>.
type callData struct {
	args [6]syscall.Arg
	caller syscall.TaskID
	phoneHash syscall.Arg
}

//extern runtime_fibril_setup
func fibril_setup() bool

//extern runtime_fibril_teardown
func fibril_teardown()

//extern async_set_client_data_constructor
func async_set_client_data_constructor(ctor func()unsafe.Pointer)

//extern async_set_client_data_destructor
func async_set_client_data_destructor(dtor func(unsafe.Pointer))

//extern async_get_client_data
func async_get_client_data() unsafe.Pointer

//extern async_get_client_data_by_id
func async_get_client_data_by_id(taskid syscall.TaskID) unsafe.Pointer

//extern async_put_client_data_by_id
func async_put_client_data_by_id(taskid syscall.TaskID)

//extern async_get_call_timeout
func async_get_call_timeout(call *callData, timeout syscall.SusecondsT) syscall.IpcCallidT

//extern async_new_connection
func async_new_connection(in_task_id syscall.TaskID, in_phone_hash syscall.Arg, callid syscall.IpcCallidT,
	call *callData, fibfunc func (syscall.IpcCallidT, *callData, unsafe.Pointer), farg unsafe.Pointer) fibril.ID

//extern async_usleep
func async_usleep(us syscall.SusecondsT)

//extern async_create_manager
func async_create_manager()

//extern async_destroy_manager
func async_destroy_manager()

//extern async_set_client_connection
func async_set_client_connection(func(cid syscall.IpcCallidT, call *callData, _ unsafe.Pointer))

//extern async_set_interrupt_received
func async_set_interrupt_received(func(syscall.IpcCallidT, *callData))

//extern async_send_fast
func async_send_fast(exch exchangePtr, imethod, arg1, arg2, arg3, arg4 syscall.Arg, dataptr *callData) syscall.AidT

//extern async_send_slow
func async_send_slow(exch exchangePtr, imethod, arg1, arg2, arg3, arg4, arg5 syscall.Arg, dataptr *callData) syscall.AidT

//extern async_wait_for
func async_wait_for(msg syscall.AidT, retval *syscall.Arg)

//extern async_wait_timeout
func async_wait_timeout(msg syscall.AidT, retval *syscall.Arg, t syscall.SusecondsT) int

//extern async_forget
func async_forget(msg syscall.AidT)

//extern async_msg_0
func async_msg_0(xchg exchangePtr, method syscall.Arg)

//extern async_msg_1
func async_msg_1(xchg exchangePtr, method, arg1 syscall.Arg)

//extern async_msg_2
func async_msg_2(xchg exchangePtr, method, arg1, arg2 syscall.Arg)

//extern async_msg_3
func async_msg_3(xchg exchangePtr, method, arg1, arg2, arg3 syscall.Arg)

//extern async_msg_4
func async_msg_4(xchg exchangePtr, method, arg1, arg2, arg3, arg4 syscall.Arg)

//extern async_msg_5
func async_msg_5(xchg exchangePtr, method, arg1, arg2, arg3, arg4, arg5 syscall.Arg)

//extern ipc_answer_fast
func ipc_answer_fast(callid syscall.IpcCallidT, retval, arg1, arg2, arg3, arg4 syscall.Arg) syscall.Arg

//extern ipc_answer_slow
func ipc_answer_slow(callid syscall.IpcCallidT, retval, arg1, arg2, arg3, arg4, arg5 syscall.Arg) syscall.Arg

//extern async_forward_fast
func async_forward_fast(callid syscall.IpcCallidT, xchg exchangePtr,
	method, arg1, arg2 syscall.Arg, mode uint) int

//extern async_forward_slow
func async_forward_slow(callid syscall.IpcCallidT, xchg exchangePtr,
	method, arg1, arg2, arg3, arg4, arg5 syscall.Arg, mode uint) int

//extern async_req_fast
func async_req_fast(xchg exchangePtr, method, arg1, arg2, arg3, arg4 syscall.Arg,
	ret1, ret2, ret3, ret4, ret5 *syscall.Arg) syscall.Errno

//extern async_req_slow
func async_req_slow(xchg exchangePtr, method, arg1, arg2, arg3, arg4, arg5 syscall.Arg,
	ret1, ret2, ret3, ret4, ret5 *syscall.Arg) syscall.Errno

//extern async_clone_establish
func async_clone_establish(mgmt ExchMgmt, xchg exchangePtr) sessionPtr

//extern async_connect_me_to
func async_connect_me_to(mgmt ExchMgmt, xchg exchangePtr, arg1, arg2, arg3 syscall.Arg) sessionPtr

//extern async_connect_me_to_blocking
func async_connect_me_to_blocking(mgmt ExchMgmt, xchg exchangePtr, arg1, arg2, arg3 syscall.Arg) sessionPtr

//extern async_connect_kbox
func async_connect_kbox(taskid syscall.TaskID) sessionPtr

//extern async_connect_to_me
func async_connect_to_me(xchg exchangePtr, arg1, arg2, arg3 syscall.Arg,
	client_receiver func(syscall.IpcCallidT, *callData, unsafe.Pointer), carg unsafe.Pointer) int

//extern async_hangup
func async_hangup(sess sessionPtr) int

//extern async_poke
func async_poke()

//extern async_exchange_begin
func async_exchange_begin(sess sessionPtr) exchangePtr

//extern async_exchange_end
func async_exchange_end(xchg exchangePtr)

//extern async_sess_args_set
func async_sess_args_set(sess sessionPtr, arg1, arg2, arg3 syscall.Arg)

//extern async_share_in_start
func async_share_in_start(xchg exchangePtr, size syscall.SizeT, arg syscall.Arg, outflags *uint, dst **byte) int

//extern async_share_in_receive
func async_share_in_receive(callid *syscall.IpcCallidT, size *syscall.SizeT) syscall.Bool

//extern async_share_in_finalize
func async_share_in_finalize(callid syscall.IpcCallidT, src *byte, flags uint) int

//extern async_share_out_receive
func async_share_out_receive(callid *syscall.IpcCallidT, size *syscall.SizeT, flags *uint) syscall.Bool

//extern async_share_out_finalize
func async_share_out_finalize(callid syscall.IpcCallidT, dst **byte) int

//extern async_data_read_receive
func async_data_read_receive(callid *syscall.IpcCallidT, size *syscall.SizeT) syscall.Bool

//extern async_data_read_finalize
func async_data_read_finalize(callid syscall.IpcCallidT, data *byte, size syscall.SizeT) int

//extern async_data_read_forward_fast
func async_data_read_forward_fast(xchg exchangePtr, method, arg1, arg2, arg3, arg4 syscall.Arg, call *callData) int

//extern async_data_write_start
func async_data_write_start(xchg exchangePtr, data *byte, size syscall.SizeT) int

//extern async_data_write_receive
func async_data_write_receive(callid *syscall.IpcCallidT, size *syscall.SizeT) syscall.Bool

//extern async_data_write_finalize
func async_data_write_finalize(callid syscall.IpcCallidT, buf *byte, size syscall.SizeT) int

//extern async_data_write_void
func async_data_write_void(retval syscall.Arg)

//extern async_data_write_forward_fast
func async_data_write_forward_fast(xchg exchangePtr, method, arg1, arg2, arg3, arg4 syscall.Arg, call *callData) int

//extern async_exchange_clone
func async_exchange_clone(exch exchangePtr, clone_exch exchangePtr) int

//extern async_clone_receive
func async_clone_receive(mgmt ExchMgmt) sessionPtr

//extern async_callback_receive
func async_callback_receive(mgmt ExchMgmt) sessionPtr

/* TODO: I have no idea what these are for.

extern async_sess_t *async_callback_receive_start(exch_mgmt_t, ipc_call_t *);

extern int async_state_change_start(async_exch_t *, sysarg_t, sysarg_t,
    sysarg_t, async_exch_t *);
extern bool async_state_change_receive(ipc_callid_t *, sysarg_t *, sysarg_t *,
    sysarg_t *);
extern int async_state_change_finalize(ipc_callid_t, async_exch_t *);

extern void *async_remote_state_acquire(async_sess_t *);
extern void async_remote_state_update(async_sess_t *, void *);
extern void async_remote_state_release(async_sess_t *);
extern void async_remote_state_release_exchange(async_exch_t *);
*/
